<?php
class Solution {
    protected $debug=false;

    /**
     * @param Integer[] $nums
     * @param Integer $k
     * @return Integer
     */
    function subarraySum($nums, $k) {
        $count=0;
        $len=sizeof($nums);

        for($i=0;$i<$len;$i++){
            $sum=0;
            for($j=$i;$j<$len;$j++){
                $sum+=$nums[$j];
                if($sum==$k) $count++;
            }
        }

        return $count;
    }

    function debug(){
        $this->debug=true;
//        return $this->subarraySum([1,2,3,4,5,6,7,1,23,21,3,1,2,1,1,1,1,1,12,2,3,2,3,2,2],12);
//        return $this->subarraySum([1, 2, 3, 4, 3, 2, 1],3);
        return $this->subarraySum([1, 2, 3],3);
    }
}